<template>
    <div class="container">
        <h3>采收管理</h3>
        <h3 v-show="$store.state.zangw=='1'">འཚོལ་བསྡུའི་དོ་དམ་</h3>
        <el-row style="margin-top:20px;">
            <el-col :span="7">
                <el-input placeholder="请输入关键词" v-model="searchName" style="width:300px;">
                    <i slot="prefix" class="el-input__icon el-icon-search" ></i>

                    <el-button slot="append" @click="handleSearch" style="background-color: #1BC46D;color: #fff;">搜索</el-button>
                </el-input>
            </el-col>
            <el-button class='theme-button' plain v-if="!added" @click="goaddrecovery" style="float:right; margin-right: 10px">新增采收</el-button>
            <!--       2024.5.27 产品说不要了         -->
            <!--                <el-upload-->
            <!--                    class="upload-daoru"-->
            <!--                    ref="upload"-->
            <!--                    action=""-->
            <!--                    :on-change="importExcel"-->
            <!--                    accept=".xlsx,.xls"-->
            <!--                    :show-file-list='false'-->
            <!--                    :auto-upload="false">-->
            <!--                    <el-button class='theme-button' slot="trigger" size="small">导入模板</el-button>-->
            <!--                </el-upload>-->
            <!--                <el-button class='theme-button' style='float: right;margin-right: 10px' @click='downloadTemplate'>下载导入模板</el-button>-->
        </el-row>
        <el-table
            :data="tableData"
            border
            style="margin-top:20px;"
            ref="multipleTable"
            header-cell-class-name="table-header"
            :header-cell-style="{ background: 'rgba(2,179,134,0.1)',color:'rgba(0,0,0,0.85)'}"
        >
            <el-table-column prop="reapName" sortable label="产出物"></el-table-column>
            <el-table-column prop="reapPart" sortable label="产出部位"></el-table-column>
            <!-- <el-table-column prop="batch" sortable label="采收批号བསྡུ་ལེན་ཆོག་མཆན་ཨང་གྲངས།"></el-table-column>
            <el-table-column prop="soilName" sortable label="种植地块གཏོགས་ཁོངས་ས་ཆ་"></el-table-column>
            <el-table-column prop="reapArea" sortable label="采收面积འཚོལ་བསྡུའི་རྒྱ་ཁྱོན།">
                <template slot-scope="scope">
                    {{scope.row.reapArea}}亩
                </template>
            </el-table-column> -->
            <el-table-column prop="batch" sortable label="采收批号"></el-table-column>
            <!--                <el-table-column prop="soilName" sortable label="种植地块"></el-table-column>-->
            <el-table-column prop="reapArea" sortable label="采收规模">
                <template slot-scope="scope">
                    {{scope.row.reapArea}}张
                </template>
            </el-table-column>
            <el-table-column prop="reapNumber" sortable label="采收数量">
                <template slot-scope="scope">
                    {{scope.row.reapNumber}}{{scope.row.units}}
                </template>
            </el-table-column>
            <el-table-column prop="beginTime" sortable label="采收时间"></el-table-column>
            <el-table-column label="操作" width="150" align="center">
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        @click="handleEdit( scope.row)"
                    >编辑</el-button>
                   <el-popconfirm title="确定删除？" @confirm="handleRemove(scope.row)">
                       <el-button
                           slot='reference'
                           type="text"
                           style='color:#e30000;margin: 0 10px'
                       >删除</el-button>
                   </el-popconfirm>
                    <el-button
                        type="text"
                        v-if="!edit"
                        @click="handleCheck(scope.$index, scope.row)"
                    >查看</el-button>

                </template>
            </el-table-column>
        </el-table>
        <el-pagination background layout="total, prev, pager, next, jumper" :page-size="pagesize" :current-page.sync="currentPage" :total="total"  @current-change="handleCurrentChange" style="margin-top:20px"></el-pagination>
        <el-dialog width='80%' :visible.sync="editShow" title="编辑">
            <edit-recovery v-if='editShow' :recoveryId='editId' @editFinish='editFinish'></edit-recovery>
        </el-dialog>
    </div>
</template>

<script>
import { reap_findByList, removeRecovery } from '@/request/api';
import editRecovery from "./editRecovery.vue"
export default {
    components:{
        editRecovery
    },
    data() {
        return {
            editId:'',
            editShow:false,


            total:0,
            currentPage:1,
            pagesize:10,
            searchName: '',
            tableData: [],
            form: {},
            idx: -1,
            id: -1,
            boxCode:'',
            boxCode1:'',
            del:true,
            added:true,
            edit:true,
            action:'',
        };
    },
    created(){

    },
    mounted(){
        this.init();
        this.judgmentAuthority();
    },
    methods: {
        //删除
        async handleRemove(params){
            const res = await removeRecovery('?id='+params.id)
            if(res.code == 200){
                this.$message.success(res.data)
                this.init()
            }
        },
        editFinish(){
            this.editShow = false
            this.init()
        },
        importExcel(file){
            let formData = new FormData();
            formData.append('file', file.raw);
            let config = {
                headers:{'Content-Type':'multipart/form-data'}
            };
            // 导入模板的接口(formData).then((res) =>{
            //     if (res.code == 200) {
            //         this.$notify({
            //             title: '操作成功',
            //             message: '导入成功',
            //             type: 'success'
            //         });
            //         this.init()
            //     } else{
            //         this.$notify.error({
            //             title: '操作失败',
            //             message: '导入失败',
            //             type: 'error'
            //         });
            //     }
            // })
        },
        downloadTemplate(){
            const companyId =  localStorage.getItem('companyId')
            let templateUrl ="/plant/template/模板下载地址&companyId="
            window.location.href = "http://47.108.220.160:90/jcApi/plant" + templateUrl + companyId
        },
        goaddrecovery(){
            this.$router.push({
                path:"/recovery/addrecovery"
            })
        },
        handleCurrentChange(val){
            this.currentPage = val
            this.init()
        },
        init(){
            let data = {
                page:this.currentPage,
                searchName:this.searchName
            }
            reap_findByList(data).then((res)=>{
                this.tableData = res.rows
                this.total = res.total
            })
        },
        handleCheck(index,row){
            this.$router.push({
                path:'/recovery/checkrecovery',
                query:{id:row.id}
            })
        },
        //搜索
        handleSearch(){
            this.currentPage = 1
            this.init()
        },
        handleEdit(params){
            console.log('编辑的数据：',params);
            this.editId = params.id
            this.editShow = true
        },

        //删除
        handleDelete(index,row){

            this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {

            });
        },
        //判定操作按钮显示
        judgmentAuthority(){
            var type = JSON.parse(localStorage.getItem("panduanzhuangtai"))
            type.map(item1 => {
                if(item1.name == '采收管理' && item1.children != null){
                    for(var i = 0; i < item1.children.length; i++){
                        if(item1.children[i].name == '新增') this.added = false;
                        if(item1.children[i].name == '查看') this.edit = false;
                    }
                }
            })
        }

    }
}
</script>

<style scoped lang="less">
/deep/.el-pagination.is-background .el-pager li:not(.disabled).active{
    background: #02B386;
}
/deep/.upload-daoru{
    background: #eee;
    .el-upload{
        border: none;
        width: auto;
        height: auto;
        border-radius: 0;
        float: right;
        margin-right: 10px
    }
}
.el-table{ margin-top: 20px;}

.el-pagination{
    text-align: right;
}
.el-col{
    margin-bottom:0;
}
</style>
